local skel = fk.CreateSkill {
  name = "emo__guizhi",
}

skel:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  prompt = "#emo__guizhi",
  target_filter = function (self, player, target, selected)
    return #selected == 0 and player ~= target and not target:isNude()
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local cardId = room:askToChooseCard(player, {target =  to, flag =  "he", skill_name = skel.name })
    to:showCards({cardId})
    if not table.contains(to:getCardIds("he"), cardId) or to.dead then return end

    local names = to:getViewAsCardNames(skel.name, Fk:getAllCardNames("td"), {cardId})
    if #names > 0 then
      local choices = table.random(names, 3)
      local use = room:askToUseVirtualCard(to, {
        name = choices, skill_name = skel.name, cancelable = true, subcards = {cardId}, skip = true,
        prompt = "#emo__guizhi-use:::"..Fk:getCardById(cardId):toLogString()  ,
      })
      if use then
        if not player.dead then
          local choice = room:askToChoice(player, {choices = choices, skill_name = skel.name, "#emo__guizhi-guess" })
          if choice == use.card.name then
            player:drawCards(2, skel.name)
          end
        end
        room:useCard(use)
        return false
      end
    end
    if not player.dead then
      room:obtainCard(player, cardId, false, fk.ReasonPrey, player, skel.name)
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__guizhi"] = "诡智",
  [":emo__guizhi"] = "出牌阶段限一次，你可以展示一名其他角色的一张牌，令其选一项：1.令你获得展示牌；2.从三个随机锦囊牌牌名中选择一个，将展示牌当所选锦囊牌使用。使用此牌前，你从这三个牌名中猜测其使用的牌，若猜对，你摸两张牌。",

  ["#emo__guizhi"] = "诡智：展示一名其他角色的一张牌，其可以转化为锦囊牌使用，或令其获得",
  ["#emo__guizhi-use"] = "诡智：将%arg转化为一个锦囊牌使用，否则交出此牌",
  ["#emo__guizhi-guess"] = "诡智：猜测其使用的锦囊牌，猜对则与其摸牌",
}


return skel
